<?php

namespace wechat;

class Js_sdk extends Wx{

//    jssdk的签名算法
    public function makesign(){
        $nocestr = $this->suiji();
        $ticket = $this->getJs_SDK();
        $timestamp = time();
        $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        $arr = [
            'noncestr=' . $nocestr,
            'jsapi_ticket=' . $ticket,
            'timestamp=' . $timestamp,
            'url=' . $url,
        ];
//        字典化排序
        sort($arr,SORT_STRING);
//        切割成字符串
//        print_r($arr);
        $string= implode($arr,'&');
//        echo $string;
        $ss = sha1($string);
        $array = [
          'timestamp'=>$timestamp,
            'nonceStr'=>$nocestr,
            'sign'=>$ss,
            'url'=>$url,
            'appid'=>'wx6a77a343ad158f41'
        ];
        return $array;
    }

//    获取随机字符串
    public function suiji(){
        $str = 'dsad131daksd34343ljk31dfgx68789550l13k1lk';
        $num = '';
        for ($i = 0;$i<8;$i++){
            $kong = mt_rand(0,strlen($str)-1);
            $num .=$str[$kong];
        }
        return $num;
    }
}




?>